﻿namespace Ex03.GarageLogic
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    public enum eVehicleState
    {
        InRepair = 1,
        Repaired = 2,
        Paid = 3
    }

    internal class GarageVehicle
    {
        #region Messages
        private const string k_Owner = "Owner name: ";
        private const string k_OwnerPhoneNumber = "Owner phone number (XXX-XXXXXXX): ";
        private const string k_NotAvailable = "N/A";
        private const string k_DisplayGarageInfo = "------ Garage Information ------";
        private const string k_DisplayOwner = "Owner name: ";
        private const string k_DisplayOwnerPhoneNumber = "Owner phone number: ";
        private const string k_DisplayCarState = "Car state: ";
        #endregion

        #region Data Members
        private readonly Vehicle r_Vehicle;
        private string m_Owner;
        private string m_OwnerPhoneNumber;
        private eVehicleState m_VehicleState;
        #endregion

        #region Constructors
        public GarageVehicle(Vehicle i_Vehicle)
        {
            r_Vehicle = i_Vehicle;
            m_Owner = k_NotAvailable;
            m_OwnerPhoneNumber = k_NotAvailable;
            m_VehicleState = eVehicleState.InRepair;
        }
        #endregion

        #region Properties
        public string LicenseNumber
        {
            get { return r_Vehicle.LicenseNumber; }
        }

        public string Owner 
        {
            get { return m_Owner; }
            set { m_Owner = value; } 
        }

        public string OwnerPhoneNumber
        {
            get { return m_OwnerPhoneNumber; }
            set { m_OwnerPhoneNumber = value; }
        }

        public eVehicleState VehicleState 
        {
            get { return m_VehicleState; }
            set { m_VehicleState = value; }
        }

        public string StringVehicleState
        {
            get 
            {
                string result = string.Empty;

                switch (m_VehicleState)
                {
                    case eVehicleState.InRepair:
                        result = "In repair";
                        break;
                    case eVehicleState.Repaired:
                        result = "Repaired";
                        break;
                    case eVehicleState.Paid:
                        result = "Paid";
                        break;
                    default:
                        break;
                }

                return result;
            }
        }

        public Vehicle Vehicle
        {
            get { return r_Vehicle; }
        }
        #endregion

        #region Public Method
        public void GetAllDetails(ref List<string> io_ListOfVehicleDetails)
        {
            io_ListOfVehicleDetails.Add(GarageLogic.s_EmptyLine);
            io_ListOfVehicleDetails.Add(k_DisplayGarageInfo);
            io_ListOfVehicleDetails.Add(k_DisplayOwner + Owner);
            io_ListOfVehicleDetails.Add(k_DisplayOwnerPhoneNumber + OwnerPhoneNumber);
            io_ListOfVehicleDetails.Add(k_DisplayCarState + StringVehicleState);
            r_Vehicle.GetAllDetails(ref io_ListOfVehicleDetails);
        }

        public void InflateToMaximum()
        {
            r_Vehicle.InfalteToMaximum();
        }

        public void FillWithFuel(eFuelType i_FuelType, float i_QuantityOfFuel)
        {
            r_Vehicle.FillWithFuel(i_FuelType, i_QuantityOfFuel);
            r_Vehicle.UpdatePercentageByEngineCurrentEnergy();
        }

        public void ChargeEnergySource(float i_MinutsToCharge)
        {
            r_Vehicle.ChargeEnergySource(i_MinutsToCharge);
            r_Vehicle.UpdatePercentageByEngineCurrentEnergy();
        }
        
        public void GetClassParametersNeededToCreate(ref List<string> io_ListOfParameters)
        {
            io_ListOfParameters.Add(k_Owner);
            io_ListOfParameters.Add(k_OwnerPhoneNumber);
            r_Vehicle.GetClassParametersNeededToCreate(ref io_ListOfParameters);
        }

        public void SetClassByParameters(ref Dictionary<string, string> io_Parameters)
        {
            if (GarageLogic.KeyFoundInDictionaryAndNotEmptyOrNull(io_Parameters, k_Owner))
            {
                Owner = io_Parameters[k_Owner];
                io_Parameters[k_Owner] = string.Empty;
            }

            if (GarageLogic.KeyFoundInDictionaryAndNotEmptyOrNull(io_Parameters, k_OwnerPhoneNumber))
            {
                OwnerPhoneNumber = io_Parameters[k_OwnerPhoneNumber];
                io_Parameters[k_OwnerPhoneNumber] = string.Empty;
            }

            r_Vehicle.SetClassByParameters(ref io_Parameters);
        }

        public override int GetHashCode()
        {
            return r_Vehicle.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            bool equals = false;
            GarageVehicle toCompareTo = obj as GarageVehicle;

            if (toCompareTo != null)
            {
                equals = r_Vehicle.Equals(toCompareTo.r_Vehicle);
            }

            return equals;
        }
        #endregion
    }
}
